#ifndef CHOOSEFRIENDWIDGET_H
#define CHOOSEFRIENDWIDGET_H

#include <QWidget>
#include <QDialog>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QScrollBar>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>
#include <QPainter>
#include <QPainterPath>

#include "debug.h"

/////////////////////////////////////
// 选择好友的窗口中的一个好友项
/////////////////////////////////////
class ChooseFriendWidget;
class ChooseFriendItem : public QWidget
{
    Q_OBJECT
public:
    ChooseFriendItem(ChooseFriendWidget *owner, const QString &userId, const QIcon &avatar, const QString &name, bool checked = false);

    void paintEvent(QPaintEvent *ev) override;
    void enterEvent(QEnterEvent *ev) override;
    void leaveEvent(QEvent *ev) override;

    QString getUserId() { return _userId; }
    QCheckBox *getCheckBox() { return _checkBox; }

private:
    bool _isHover = false;

    ChooseFriendWidget *_owner;

    QCheckBox *_checkBox;
    QPushButton *_avatarBtn;
    QLabel *_nameLabel;

    QString _userId;
};

/////////////////////////////////////
// 选择好友的窗口
/////////////////////////////////////
class ChooseFriendWidget : public QDialog
{
    Q_OBJECT
public:
    ChooseFriendWidget(QWidget *parent = nullptr);

    void addFriend(const QString &userId, const QIcon &avatar, const QString &name, bool checked = false);
    void addSelectFriend(const QString &userId, const QIcon &avatar, const QString &name);
    void deleteSelectFriend(const QString &userId);

private:
    void initLeft(QHBoxLayout *layout);
    void initRight(QHBoxLayout *layout);

private:
    // 左侧全部好友的widget
    QWidget *_totalContainer;
    // 左侧选中好友的widget
    QWidget *_chooseContainer;
};

#endif // CHOOSEFRIENDWIDGET_H
